package org.mymybatis.core;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.io.InputStream;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: mySSM
 * @description: SqlSession工厂，一个数据库对应一个sqlSessionFactory对象
 * @author:wjp
 * @create: 2025-02-15 23:02
 **/
public class SqlSessionFactory {

    /**
     * 事物管理器对象，由于管理器类型是可切换的
     * 如JDBCTransactionManager或ManagedTransaction
     * 因此此处设计为接口，可根据配置不同设置不同类型的对象
     */
    private Transaction transaction;

    private Map<String,MappedStatement> mappedStatements = new HashMap<String,MappedStatement>();

    public SqlSessionFactory() {
    }

    public SqlSessionFactory(Transaction transaction, Map<String, MappedStatement> mappedStatements) {
        this.transaction = transaction;
        this.mappedStatements = mappedStatements;
    }

    public Transaction getTransaction() {
        return transaction;
    }

    public void setTransaction(Transaction transaction) {
        this.transaction = transaction;
    }

    public Map<String, MappedStatement> getMappedStatementMap() {
        return mappedStatements;
    }

    public void setMappedStatementMap(Map<String, MappedStatement> mappedStatements) {
        this.mappedStatements = mappedStatements;
    }


    public SqlSession openSession() throws SQLException {
        return new SqlSession(this);
    }
}
